
#ifndef	__KC_FEKCAB_TIME_STAMP_HPP_2010__
#define	__KC_FEKCAB_TIME_STAMP_HPP_2010__

#include <sys/time.h>
#include <sstream>

namespace	fekcab	{


typedef	struct timeval	timeval_type;

class	Timestamp
{

public	:
	
	Timestamp() 
	{
		gettimeofday( &_tv, NULL );
	}

	Timestamp( const struct timeval tv ) 
	{
		_tv = tv;
	}

	Timestamp( time_t t )
	{
		_tv.tv_sec = t;
		_tv.tv_usec = 0;
	}

public	:
	bool	operator<( const Timestamp& rhs )
	{
		return ( (_tv.tv_sec < rhs._tv.tv_sec) || 
				 ((_tv.tv_sec == rhs._tv.tv_sec) && (_tv.tv_usec < rhs._tv.tv_usec))
			   );
	}

	bool	operator==( const Timestamp& rhs )
	{
		return	( (_tv.tv_sec == rhs._tv.tv_sec) && (_tv.tv_usec == rhs._tv.tv_usec) );
	}

	bool	operator!=( const Timestamp& rhs )
	{
		return	( (_tv.tv_sec != rhs._tv.tv_sec) || (_tv.tv_usec != rhs._tv.tv_usec) );
	}

	bool	operator<( const timeval_type& rhs )
	{
		return ( (_tv.tv_sec < rhs.tv_sec) || 
				 ((_tv.tv_sec == rhs.tv_sec) && (_tv.tv_usec < rhs.tv_usec))
			   );
	}

	bool	operator==( const timeval_type& rhs )
	{
		return	( (_tv.tv_sec == rhs.tv_sec) && (_tv.tv_usec == rhs.tv_usec) );
	}

	bool	operator!=( const timeval_type& rhs )
	{
		return	( (_tv.tv_sec != rhs.tv_sec) || (_tv.tv_usec != rhs.tv_usec) );
	}

public	:

	void*	data( void )
	{
		return	(void *)&_tv;
	}

	const void*	data( void ) const
	{
		return	(const void *)&_tv;
	}

	const u_int32_t	size( void ) const
	{
		return	sizeof(struct timeval);
	}


public	:
	std::string	str()
	{
		std::ostringstream	msg;
		msg << "(" << _tv.tv_sec << "," << _tv.tv_usec << ")";
		return msg.str();
	}

	const std::string	str() const
	{
		std::ostringstream	msg;
		msg << "(" << _tv.tv_sec << "," << _tv.tv_usec << ")";
		return msg.str();
	}

public	:
	timeval_type	timeval( void )
	{
		return	_tv;
	}

	const timeval_type	timeval( void ) const
	{
		return	_tv;
	}

private	:
	timeval_type	_tv;

};	//// class Timestamp


}	//// namespace fekcab

#endif	//	__KC_FEKCAB_TIME_STAMP_HPP_2010__

